﻿#pragma once

#include "common.h"
#include "mixer.h"

namespace anip
{
	namespace audio
	{
		class HarmonicOscillator
		{
		private:
			int _sampleRate = 44100;
			int _channels = 2;

			class Instance : public SoundInstance
			{
			private:
				HarmonicOscillator& _osc;
				const double _freq;
				const double _length;

			public:
				Instance(HarmonicOscillator& w, double freq, double l) :
					_osc(w), _freq(freq), _length(l) {}

				int channelCount() const { return _osc._channels; }
				bool read(double* dest, unsigned int nSamples, unsigned int start);
			};

		public:
			struct Harmonic
			{
				double octave = 0;
				double amplitude = 1;
				double timeOffset = 0;
			};

			std::vector<Harmonic> harmonics{ {0, 1, 0} };

			SoundInstance* instantiate(double freq, double l) 
			{ 
				return new Instance(*this, freq, l); 
			}

			void setSampleRate(int rate) { _sampleRate = rate; }
			int sampleRate() const { return _sampleRate; }
			void setChannels(int n) { _channels = n; }
			int channelCount() const { return _channels; }
		};
	}
}